package com.yanghui.lingyue.data

import com.icedata.sika.database.Column
import com.icedata.sika.database.Table
import com.yanghui.lingyue.bot.Bot
import java.util.*

@Table("[Function]", "", "name")
data class Function(
    @Column("name")
    var name: String,

    @Column("antiChoose")
    var antiChoose: Boolean,

    @Column("enableGroup")
    var enableGroup: String,

    @Column("disableGroup")
    var disableGroup: String
) {

    var enableGroupList: LinkedList<Long> = LinkedList()

    constructor():this("",false,"","")

    fun init(){
        if (!antiChoose) {
            enableGroup.split(",").forEach {
                enableGroupList.add(it.toLong())
            }
        } else {
            val disableGroupList = disableGroup.split(",")
            Bot.groupList.forEach { id, _ ->
                if (id.toString() !in disableGroupList) {
                    enableGroupList.add(id)
                }
            }
        }
    }
}